var spinner;

var companyCode = localStorage.getItem("companyCode")

function showDialog() {
	var opts = {
		lines: 13, // 花瓣数目
		length: 10, // 花瓣长度
		width: 5, // 花瓣宽度
		radius: 15, // 花瓣距中心半径
		scale: 1,
		corners: 1, // 花瓣圆滑度 (0-1)
		color: '#000', // 花瓣颜色
		opacity: 0.25,
		rotate: 0, // 花瓣旋转角度
		direction: 1, // 花瓣旋转方向 1: 顺时针, -1: 逆时针
		speed: 1, // 花瓣旋转速度
		trail: 60, // 花瓣旋转时的拖影(百分比)
		zIndex: 2e9, // spinner的z轴 (默认是2000000000)
		className: 'spinner', // spinner css 样式名称
		top: '350%', // spinner 相对父容器Top定位 单位 px
		shadow: true, // 花瓣是否显示阴影
		hwaccel: false, //spinner 是否启用硬件加速及高速旋转
		position: 'absolute'
	};
	spinner = new Spinner(opts);
	$(".spin").show();
	var target = $(".spin")[0];
	spinner.spin(target);
}

function dismissDialog() {
	if(spinner != undefined) {
		spinner.spin();
	}
}

var UTFTranslate = {
	Change: function(pValue) {
		return pValue.replace(/[^\u0000-\u00FF]/g, function($0) {
			return escape($0).replace(/(%u)(\w{4})/gi, "&#x$2;")
		});
	},
	ReChange: function(pValue) {
		return unescape(pValue.replace(/&#x/g, '%u').replace(/\\u/g, '%u').replace(/;/g, ''));
	}
};





function disp_prompt() {
	var name = prompt("请扫描您的二维码", " "); // 弹出input框
	if(name == ' ') {
		return;
	} else {
		mui.alert(name);
	}
}

function encryptByDES(message) {
	//把私钥转换成16进制的字符串
	var keyHex = CryptoJS.enc.Utf8.parse('com.nokia.parts');
	//模式为ECB padding为Pkcs7
	var encrypted = CryptoJS.DES.encrypt(message, keyHex, {
		mode: CryptoJS.mode.ECB,
		padding: CryptoJS.pad.Pkcs7
	});
	//加密出来是一个16进制的字符串
	return encrypted.ciphertext.toString();
}
//DES  ECB模式解密
function decryptByDESModeEBC(ciphertext) {
	//把私钥转换成16进制的字符串
	var keyHex = CryptoJS.enc.Utf8.parse('com.nokia.parts');
	//把需要解密的数据从16进制字符串转换成字符byte数组
	var decrypted = CryptoJS.DES.decrypt({
		ciphertext: CryptoJS.enc.Hex.parse(ciphertext)
	}, keyHex, {
		mode: CryptoJS.mode.ECB,
		padding: CryptoJS.pad.Pkcs7
	});
	//以utf-8的形式输出解密过后内容
	var result_value = decrypted.toString(CryptoJS.enc.Utf8);
	return result_value;
}

function shouye() {
	window.location.href = "homePage.html";
}

function tuichu() {
	var keys = JSON.parse(localStorage.getItem('key'));
	var htmlobj = $.ajax({
		url: "cabinetCode.txt",
		async: false
	});
	$.ajax({
		type: "POST",
		url: url_prefix + "smart_Loginout",
		dataType: 'JSON',
		data: {
			'request': encryptByDES("{\"cabinetCode\":\"" + htmlobj.responseText + "\",\"key\":\"" + keys + "\"}")
		},
		success: function(data) {
			var str1 = decryptByDESModeEBC(data["result"]); //解密
			var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
			var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
			var datas = JSON.stringify(str2); //转JSON字符串
			var aa = datas.replace(/\\n/g, " "); //去掉换行
			var objs = eval('(' + aa + ')');
			var bb = eval('(' + objs + ')');
			if(bb.head.status == 1) {
				window.location.href = "signIn.html";
			} else {
				mui.alert(bb.head.info);
			}
		}
	});
}

function search() {
	if(null == document.getElementById("seachText").value || '' == document.getElementById("seachText").value) {
		return;
	}
	var locationData = JSON.parse(localStorage.getItem('projectData'));
	var logdata = JSON.parse(localStorage.getItem('LoginData'));
	var inputTest = $("#seachText").val();
	var page = "0";
	var userName = logdata.userLogin;
	var netId = locationData.netId;
	var projectName = locationData.projectName;
	var size = "200";
	var flag = "1";

	$.ajax({
		type: "POST",
		url: url_prefix + "searchSiteListGis.action?",
		dataType: 'JSON',
		data: {
			//                "page": "0",
			//    "searchKey": "家",
			//    "userName": "admin",
			//    "netId": "1",
			//    "projectName": "上海联通",
			//    "size": "10"
			'request': "{\"searchKey\":\"" + inputTest + "\",\"page\":\"" + page + "\",\"userName\":\"" + userName + "\",\"netId\":\"" + netId + "\",\"projectName\":\"" + projectName + "\",\"size\":\"" + size + "\",\"flag\":\"" + flag + "\"}"

		},
		success: function(data) {
			var str1 = data["result"]; //解密
			//            var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
			//            var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
			//            var datas = JSON.stringify(str2); //转JSON字符串
			//            var aa = datas.replace(/\\n/g, " "); //去掉换行
			//            var objs = eval('(' + aa + ')');
			//            var bb = eval('(' + objs + ')');

			if(str1.head.status == 1) {
				console.log(str1);
				insertDataforv(str1.data);

			} else {
				alert(str1.head.info);
				if(str1.head.info == "登录已失效!") {
					window.location.href = 'login.html';
				}
			}

		}
	});
}

function insertDataforv(str1) {
	var noApplicationRecord = document.getElementById('noApplicationRecord');
	if(str1.length * 35 > 500) {
		noApplicationRecord.style = "overflow-x:hidden;overflow-y:auto;height: 500px;"
	}

	function setDiv(item, i) {
		var div = '<div id="' + i + '" onclick="selectAction()" class="mohucx"><p>' +
			item.cellName +
			'</p></div>'
		return div;
	}

	function getnoApplicationData() {
		var html = ''
		for(var i = 0; i < str1.length; i++) {
			html += setDiv(str1[i], i)
		}
		noApplicationRecord.innerHTML = html
	}
	window.onload = getnoApplicationData();

}

function hideseach() {
	var div1 = document.getElementById("guanbi");
	div1.style.display = 'none';
}

function verifyMobile(val) {
	var p1 = /^[0-9]{3,16}$/;  
    var me = false;  
    if (p1.test(val)) {
    	me=true;
    }
    return me
}



// 搜索站点
function siteSeach() {

	if(null == document.getElementById("siteInpute").value || '' == document.getElementById("siteInpute").value) {
		return;
	}
	var locationData = JSON.parse(localStorage.getItem('projectData'));
	var logdata = JSON.parse(localStorage.getItem('LoginData'));

	var inputTest = $("#siteInpute").val();
	var page = "0";
	var userName = logdata.userLogin;
	var netId = locationData.netId;
	var projectName = locationData.projectName;

	var size = "100";
	var flag = "0"; //1则不匹配告警和KPI信息 (其他则默认匹配)

	$.ajax({
		type: "POST",
		url: url_prefix + "searchSiteListGis.action?",
		dataType: 'JSON',
		data: {
			//                "page": "0",
			//    "searchKey": "家",
			//    "userName": "admin",
			//    "netId": "1",
			//    "projectName": "上海联通",
			//    "size": "10"
			'request': "{\"searchKey\":\"" + inputTest + "\",\"page\":\"" + page + "\",\"userName\":\"" + userName + "\",\"netId\":\"" + netId + "\",\"projectName\":\"" + projectName + "\",\"size\":\"" + size + "\",\"flag\":\"" + flag + "\"}"

		},
		success: function(data) {
			var str1 = data["result"]; //解密
			//            var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
			//            var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
			//            var datas = JSON.stringify(str2); //转JSON字符串
			//            var aa = datas.replace(/\\n/g, " "); //去掉换行
			//            var objs = eval('(' + aa + ')');
			//            var bb = eval('(' + objs + ')');

			if(str1.head.status == 1) {
				console.log(str1);
				selectSite(str1.data);

			} else {
				alert(str1.head.info);
				if(str1.head.info == "登录已失效!") {
					window.location.href = 'login.html';
				}
			}
		}

	});

}

function selectSite(data) {
	localStorage.setItem('siteData', JSON.stringify(data));
	var noApplicationRecord = document.getElementById('siteseach');
	if(data.length * 35 > 500) {
		noApplicationRecord.style = "overflow-x:hidden;overflow-y:auto;height: 500px;"
	}

	function setDiv(item, i) {
		var div = '<div id="' + i + '" onclick="SelectSite(' + i + ')" class="mhcx-ss"><p>' +
			item.cellName +
			'</p></div>'
		return div;
	}

	function getnoApplicationData() {
		var html = ''
		for(var i = 0; i < data.length; i++) {
			html += setDiv(data[i], i)
		}
		noApplicationRecord.innerHTML = html
	}
	window.onload = getnoApplicationData();
}

function SelectSite(i) {
	var div = document.getElementById("siteseach");
	div.style.display = 'none';

	var div = document.getElementById("siteResult");
	div.style.display = "table";

	var seachData = JSON.parse(localStorage.getItem('siteData'));
	var sss = seachData[i];
	localStorage.setItem('cellinfo', JSON.stringify(sss));
	seachsiteMap(BMAP_HYBRID_MAP);

	var noApplicationRecord = document.getElementById('siteinfomation');
	if(sss.length * 32 > 100) {
		noApplicationRecord.style = "overflow-x:hidden;overflow-y:auto;height: 100px;"
	}

	function setDiv(sss) {
		var div = '<tr class = "tab-tr-hover"><td>' + sss.cellName + '</td><td>' + sss.siteID + '</td></tr>'
		return div;
	}

	function getnoApplicationData() {
		var html = '';
		html += setDiv(sss);
		noApplicationRecord.innerHTML = html
	}
	window.onload = getnoApplicationData();

}

function seachCI() {
	if(null == document.getElementById("siteInpute").value || '' == document.getElementById("siteInpute").value) {
		return;
	}
	var locationData = JSON.parse(localStorage.getItem('projectData'));
	var logdata = JSON.parse(localStorage.getItem('LoginData'));

	var inputTest = $("#siteInpute").val();
	var page = "0";
	var userName = logdata.userLogin;
	var netId = locationData.netId;
	var projectName = locationData.projectName;

	var size = "100";
	var flag = "1";

	$.ajax({
		type: "POST",
		url: url_prefix + "searchSiteListGis.action?",
		dataType: 'JSON',
		data: {
			//                "page": "0",
			//    "searchKey": "家",
			//    "userName": "admin",
			//    "netId": "1",
			//    "projectName": "上海联通",
			//    "size": "10"
			'request': "{\"searchKey\":\"" + inputTest + "\",\"page\":\"" + page + "\",\"userName\":\"" + userName + "\",\"netId\":\"" + netId + "\",\"projectName\":\"" + projectName + "\",\"size\":\"" + size + "\",\"flag\":\"" + flag + "\"}"

		},
		success: function(data) {
			var str1 = data["result"]; //解密

			if(str1.head.status == 1) {
				console.log(str1);
				seachResult(str1.data);
			} else {
				alert(str1.head.info);
				if(str1.head.info == "登录已失效!") {
					window.location.href = 'login.html';
				}
			}

		}
	});

}

function seachResult(data) {
	localStorage.setItem('siteData', JSON.stringify(data));
	var noApplicationRecord = document.getElementById('seachData');
	if(data.length * 35 > 500) {
		noApplicationRecord.style = "overflow-x:hidden;overflow-y:auto;height: 500px;"
	}

	function setDiv(item, i) {
		var div = '<div id="' + i + '" onclick="SelectchaxunCI(' + i + ')" class="mhcx-ss"><p>' +
			item.cellName +
			'</p></div>'
		return div;
	}

	function getnoApplicationData() {
		var html = ''
		for(var i = 0; i < data.length; i++) {
			html += setDiv(data[i], i)
		}
		noApplicationRecord.innerHTML = html
	}
	window.onload = getnoApplicationData();
}

// 经纬度测量选择小区后
function SelectchaxunCI(i) {
	var div = document.getElementById("seachData");
	div.style.display = 'none';

	var div = document.getElementById("guanbi");
	div.style.display = 'none';

	var seachData = JSON.parse(localStorage.getItem('siteData'));
	var sss = seachData[i];

	localStorage.setItem('cellinfo', JSON.stringify(sss));
	// 获得GPS坐标
	getCellInfo(0);

}
// 上传经纬度测试数据
function uploadData(data, lat, lon) {
	var locationData = JSON.parse(localStorage.getItem('projectData'));
	var logdata = JSON.parse(localStorage.getItem('LoginData'));
	var token = logdata.token;
	var projectId = locationData.projectId;
	var ci = data.ci;
	var latitude = lat;
	var longitude = lon;

	var projectName = locationData.projectName;
	var netId = data.netId;

	$.ajax({
		type: "POST",
		url: url_prefix + 'updateAntennaInfo.action?',
		dataType: 'JSON',
		data: {
			//                "page": "0",
			//    "searchKey": "家",
			//    "userName": "admin",
			//    "netId": "1",
			//    "projectName": "上海联通",
			//    "size": "10"
			'request': "{\"ci\":\"" + ci + "\",\"token\":\"" + token + "\",\"projectId\":\"" + projectId + "\",\"latitude\":\"" + latitude + "\",\"longitude\":\"" + longitude + "\",\"projectName\":\"" + projectName + "\",\"netId\":\"" + netId + "\"}"

		},
		success: function(data) {
			var str1 = data["result"]; //解密
			//            var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
			//            var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
			//            var datas = JSON.stringify(str2); //转JSON字符串
			//            var aa = datas.replace(/\\n/g, " "); //去掉换行
			//            var objs = eval('(' + aa + ')');
			//            var bb = eval('(' + objs + ')');
			if(str1.head.status == 1) {

				console.log(str1);
				mui.alert('数据上传成功', '提示');

			} else {
				alert(str1.head.info);
				if(str1.head.info == "登录已失效!") {
					window.location.href = 'login.html';
				}
			}
		}
	});
}

// 工参查询
function getCellInfo(issitechaxun) {
	var info = JSON.parse(localStorage.getItem('cellinfo'));
	var ci = info.ci;

	var locationData = JSON.parse(localStorage.getItem('projectData'));
	var logdata = JSON.parse(localStorage.getItem('LoginData'));
	var token = logdata.token;
	var projectId = locationData.projectId;
	var userName = logdata.userLogin;
	var netId = info.netId;
	//  var netId = locationData.netId;
	var projectName = locationData.projectName;

	$.ajax({
		type: "POST",
		url: url_prefix + "getCellInfo.action?",
		dataType: 'JSON',
		data: {
			//                "page": "0",
			//    "searchKey": "家",
			//    "userName": "admin",
			//    "netId": "1",
			//    "projectName": "上海联通",
			//    "size": "10"
			'request': "{\"ci\":\"" + ci + "\",\"userName\":\"" + userName + "\",\"netId\":\"" + netId + "\",\"projectName\":\"" + projectName + "\"}"

		},
		success: function(data) {

			var str1 = data["result"]; //解密
			//            var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
			//            var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
			//            var datas = JSON.stringify(str2); //转JSON字符串
			//            var aa = datas.replace(/\\n/g, " "); //去掉换行
			//            var objs = eval('(' + aa + ')');
			//            var bb = eval('(' + objs + ')');
			if(str1.head.status == 1) {
				localStorage.setItem('ci', ci);
				localStorage.setItem('getCellInfo', JSON.stringify(str1.data));
				if(issitechaxun == 1) {
					window.location.href = "gongcan.html";
				} else {
					ciMap(BMAP_NORMAL_MAP);
				}

				console.log(str1);

			} else {
				alert(str1.head.info);
				if(str1.head.info == "登录已失效!") {
					window.location.href = 'login.html';
				}
			}
		}
	});
}

// 告警查询
function getgaojing() {
	var info = JSON.parse(localStorage.getItem('cellinfo'));
	var ci = info.ci;

	var locationData = JSON.parse(localStorage.getItem('projectData'));
	var logdata = JSON.parse(localStorage.getItem('LoginData'));
	var token = logdata.token;
	var projectId = locationData.projectId;
	var type = 'alarm';
	var projectName = locationData.projectName;
	var outLevel = '0';
	var siteId = info.siteID;
	$.ajax({
		type: "POST",
		url: url_prefix + "getKpiOrAlarm.action?",
		dataType: 'JSON',
		data: {
			//                "page": "0",
			//    "searchKey": "家",
			//    "userName": "admin",
			//    "netId": "1",
			//    "projectName": "上海联通",
			//    "size": "10"
			'request': "{\"cellId\":\"" + ci + "\",\"type\":\"" + type + "\",\"siteId\":\"" + siteId + "\",\"outLevel\":\"" + outLevel + "\",\"projectId\":\"" + projectId + "\",\"token\":\"" + token + "\",\"enbid\":\"" + siteId + "\"}"

		},
		success: function(data) {

			var str1 = data["result"]; //解密
			//            var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
			//            var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
			//            var datas = JSON.stringify(str2); //转JSON字符串
			//            var aa = datas.replace(/\\n/g, " "); //去掉换行
			//            var objs = eval('(' + aa + ')');
			//            var bb = eval('(' + objs + ')');
			if(str1.head.status == 1) {
				//                localStorage.setItem('ci',ci);
				localStorage.setItem('gaojindata', JSON.stringify(str1.data));
				window.location.href = "gaojing.html";
				console.log(str1);

			} else {
				alert(str1.head.info);
				if(str1.head.info == "登录已失效!") {
					window.location.href = 'login.html';
				}
			}
		}
	});

}

// KPI查询
function getKpI() {
	var info = JSON.parse(localStorage.getItem('cellinfo'));
	var ci = info.ci;

	var locationData = JSON.parse(localStorage.getItem('projectData'));
	var logdata = JSON.parse(localStorage.getItem('LoginData'));
	var token = logdata.token;
	var projectId = locationData.projectId;
	var type = 'kpi';
	var projectName = locationData.projectName;
	var outLevel = '0';
	var siteId = info.siteID;
	var netId = info.netId;
	$.ajax({
		type: "POST",
		url: url_prefix + "getKpiOrAlarm.action?",
		dataType: 'JSON',
		data: {
			//                "page": "0",
			//    "searchKey": "家",
			//    "userName": "admin",
			//    "netId": "1",
			//    "projectName": "上海联通",
			//    "size": "10"
			'request': "{\"cellId\":\"" + ci + "\",\"type\":\"" + type + "\",\"siteId\":\"" + siteId + "\",\"outLevel\":\"" + outLevel + "\",\"projectId\":\"" + projectId + "\",\"token\":\"" + token + "\",\"enbid\":\"" + siteId + "\"}"

		},

		success: function(data) {
			var str1 = data["result"]; //解密
			//            var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
			//            var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
			//            var datas = JSON.stringify(str2); //转JSON字符串
			//            var aa = datas.replace(/\\n/g, " "); //去掉换行
			//            var objs = eval('(' + aa + ')');
			//            var bb = eval('(' + objs + ')');
			if(str1.head.status == 1) {
				//                localStorage.setItem('ci',ci);
				localStorage.setItem('KPIdata', JSON.stringify(str1.data));
				window.location.href = "KPI.html";
				console.log(str1);

			} else {
				alert(str1.head.info);
				if(str1.head.info == "登录已失效!") {
					window.location.href = 'login.html';
				}
			}
		}
	});

}

function hidejizhanicon() {

	$('#5gjizhan').hide()
	$('#4gjizhan').hide()
	$('#3gjizhan').hide()
	$('#2gjizhan').hide()

	//	            var sangjizhan = document.getElementById('3gjizhan');
	//				sangjizhan.style.display = 'none';
	//				var sigjizhan = document.getElementById('4gjizhan');
	//				sigjizhan.style.display = 'none';
	//				var towgjizhan = document.getElementById('2gjizhan');
	//				towgjizhan.style.display = 'none';
	//				var wugjizhan = document.getElementById('5gjizhan');
	//				wugjizhan.style.display = 'none';

}